package com.iwhalecloud.bss.kite.cucc.service.attr.handler;
import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.util.KiteBeanUtils;
import com.iwhalecloud.bss.kite.common.util.KiteObjectUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.dataservice.cache.AttrValueCache;
import com.iwhalecloud.bss.kite.dataservice.entity.AttrValue;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.enums.InstType;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttrValue;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteProdInstFunc;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;
import com.iwhalecloud.bss.kite.service.scene.attr.OperateInstAttrService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 订购5G产品，通信计划配置界面展示“使用切片”属性
 */
public class UseSliceAttrHandler extends AbstractAttrHandler<KiteProdInstFunc, AttrData> {
    @Autowired
    private IQuerySceneInstService querySceneInstService;
    @Autowired
    private OperateInstAttrService operateInstAttrService;

    @Override
    public void def(KiteAttr attr, KiteProdInstFunc inst, AttrData data) {
        String custId = data.getCustId();
        KiteInst kiteInst = querySceneInstService
            .getKiteInst(custId, InstType.PROD_INST, inst.getAccProdInstId());
        if (!KiteObjectUtils.isEmpty(kiteInst)) {
            KiteAttr attrOther = kiteInst.getAttr("200003674");
            if (!KiteObjectUtils.isEmpty(attrOther)) {
                if (KiteStringUtils.equals("1_0000102", attrOther.getValue())) {
                    attr.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_D);
                    attr.setIsNull(KeyConsts.IFTRUE_F);
                    attr.setDefaultValue("100007414");
                    attr.setValue("100007414");
                    operateInstAttrService.setAttrValue(inst, attr.getFieldName(), "100007414", data.getSceneInstId(), null);

                    List<AttrValue> attrValueList = AttrValueCache.get("20201205011");
                    List<KiteAttrValue> kiteAttrValueList = KiteBeanUtils.copyPropsForList(attrValueList, KiteAttrValue.class);
                    attr.setAttrValues(kiteAttrValueList);
                }
            }
        }
        super.def(attr, inst, data);
    }

}
